<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="/common/user.jsp"%>
<%@ include file="/common/sms.jsp"%>
<%@ include file="/common/huanxin.jsp"%>
<%
    String phone = input.getDesc("phone", "");
    if (!phone.equals("")) {
      String code = input.getDesc("code");
      Message codeMsg = validateSms(phone, code, REGISTER_SMS, hospital);
      if (codeMsg.getErrcode() != 0) {
         Tools.encryptPrint(out, codeMsg);
         return;
      }
    }
    User user = User.fromMap(parameters, User.class);
	if (isChinaPhoneLegal(user.getPhone())) {
		user.setUserName(generateUserName(user.getPhone()));
	}
    if (user.getType() != null && user.getType() == 200) {
        Tools.encryptPrint(out, new Message(30031, "暂未开放注册"));
        return;
    }
    UserProfile userProfile = UserProfile.fromMap(parameters, UserProfile.class);
    msg = register(user, userProfile);
	String app = input.getDesc("application", "");
	if (!"".equals(app) && msg.getErrcode() == 0) {
		register(((Map)msg.get("data")).get("uid") + "", "123456", app, hospital);
	}
    Tools.encryptPrint(out, msg);
%>
